package com.jinsp.webviewservice.util;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * Created by luoshuai on 12/30/21
 * <p>
 * 网络工具类
 */
public class NetUtils {

    /**
     * 判断网络是否连接
     *
     * @param context 上下文
     * @return true -- 网络连接
     */
    public static boolean isNetworkConnected(Context context) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        assert connectivityManager != null;
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        return (networkInfo != null && networkInfo.isConnected());
    }
}
